<script setup lang="ts">
import { ref } from "vue";
import { useRole } from "./hook";
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import { regionData, provinceAndCityData } from "@/utils/chinaArea";

import CustomerDetail from "@/components/customerDetail/index.vue"

import Eye from "~icons/ri/Eye-line";
import Refresh from "~icons/ep/refresh";
import { SuccessFilled,CircleCloseFilled } from "@element-plus/icons-vue";
import Checkbox from "~icons/ri/checkbox-fill";
defineOptions({
  name: "CustomerDataDiscardPool"
});

const formRef = ref();
const detailRef = ref();
const {
  permissions,

  shortcuts,
  labelList,
  sourceList,
  userList,
  form,
  loading,
  tableRef,
  columns,
  dataList,
  pagination,
  multipleSelection,
  handleSelectionClear,
  agreeDiscard,
  refuseDiscard,

  handleSelectionChange,
  onSearch,
  resetForm,
  lookCustomer,
  handleSizeChange,
  handleCurrentChange
} = useRole(detailRef);
</script>

<template>
  <div class="main">
    <div class="mb-[12px] bg-[#fff] p-[12px]">
      <el-radio-group v-model="form.deal_status" size="large" @change="onSearch">
        <el-radio-button label="未处理" :value="0" />
        <el-radio-button label="已同意" :value="1" />
        <el-radio-button label="已拒绝" :value="2" />
      </el-radio-group>
    </div>
    <el-form
      ref="formRef"
      :inline="true"
      :model="form"
      class="search-form bg-bg_color w-full pl-8 pt-[12px] overflow-auto"
    >
      <el-form-item prop="keyword">
        <el-input
          v-model="form.keyword"
          placeholder="客户名/企业名/手机号"
          clearable
          class="w-[180px]!"
        />
      </el-form-item>
      <el-form-item prop="tag_id">
        <el-select
          v-model="form.tag_id"
          placeholder="客户标签"
          clearable
          class="w-[120px]!"
        >
          <el-option v-for="(item, index) in labelList" :key="index" :label="item.name" :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item prop="address">
        <el-cascader
          v-model="form.address"
          placeholder="所在地区"
          :options="regionData"
          :props="{ checkStrictly: true, value: 'label' }"
          clearable
          class="w-[120px]!"
        />
      </el-form-item>
      <el-form-item v-if="permissions.is_cd_fq_table">
        <el-button
          type="primary"
          :icon="useRenderIcon('ri/search-line')"
          :loading="loading"
          @click="onSearch"
        >
          查询
        </el-button>
        <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)">
          重置
        </el-button>
      </el-form-item>
    </el-form>

    <PureTableBar
      title=""
      :columns="columns"
      @refresh="onSearch"
    >
      <template v-slot="{ size, dynamicColumns }">
        <div class="multipleInner" v-if="multipleSelection.length">
          <IconifyIconOffline
            :icon="Checkbox"
            style="color: #fff; width: 18px; height: 18px; cursor: pointer"
            @click="handleSelectionClear"
          />
          <b>已选中 {{ multipleSelection.length }} 项</b>
          <div class="multipHandle" @click="agreeDiscard" v-if="form.deal_status == 0">
            <el-icon><SuccessFilled /></el-icon>
            <p>同意废弃申请</p>
          </div>
          <div class="multipHandle" @click="refuseDiscard" v-if="form.deal_status == 0">
            <el-icon><CircleCloseFilled /></el-icon>
            <p>拒绝废弃申请</p>
          </div>
          <!-- <div class="multipHandle" @click="lockClick" v-if="permissions.is_cd_gj_lock">
            <IconifyIconOffline :icon="Lock" />
            <p>锁定</p>
          </div>
          <div class="multipHandle" @click="transferClick" v-if="permissions.is_cd_gj_transfer">
            <IconifyIconOffline :icon="Arrowleftright" />
            <p>转移给他人</p>
          </div>
          <div class="multipHandle" @click="releaseClick" v-if="permissions.is_cd_gj_release">
            <IconifyIconOffline :icon="Share" />
            <p>释放到公海</p>
          </div> -->
        </div>
        <pure-table
          ref="tableRef"
          align-whole="center"
          showOverflowTooltip
          table-layout="auto"
          :loading="loading"
          :size="size"
          adaptive
          :adaptiveConfig="{ offsetBottom: 108 }"
          :data="dataList"
          :columns="dynamicColumns"
          :pagination="{ ...pagination, size }"
          :header-cell-style="{
            background: 'var(--el-fill-color-light)',
            color: 'var(--el-text-color-primary)'
          }"
          @page-size-change="handleSizeChange"
          @page-current-change="handleCurrentChange"
          @selection-change="handleSelectionChange"
        >
          <template #operation="{ row }">
            <el-button
              class="reset-margin"
              link
              type="primary"
              :size="size"
              :icon="useRenderIcon(Eye)"
              @click="lookCustomer(row)"
            >
            </el-button>
          </template>
        </pure-table>
      </template>
    </PureTableBar>

    <CustomerDetail ref="detailRef"></CustomerDetail>
  </div>
</template>

<style lang="scss" scoped>
:deep(.el-dropdown-menu__item i) {
  margin: 0;
}

:deep(.el-form--inline .el-form-item) {
  margin-right: 12px;
}

.main {
  margin: 12px 12px 0 !important;
}

.search-form {
  :deep(.el-form-item) {
    margin-bottom: 12px;
  }
}
.multipleInner {
  background-color: var(--pure-theme-menu-active-before);
  height: 45px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-size: 14px;
  color: #ffffff;

  b {
    margin-left: 3px;
    margin-right: 10px;
  }

  .multipHandle {
    padding: 5px 8px;
    margin-left: 10px;
    display: flex;
    align-items: start;
    cursor: pointer;
    border-radius: 5px;
    transition: all 0.1s;

    svg {
      font-size: 16px;
      color: #ffffff;
      margin-top: 2px;
    }

    p {
      margin-left: 5px;
    }

    &:hover {
      background-color: #ffffff;
      color: #000000;

      :deep(svg) {
        color: #000000;
      }
    }
  }
}
</style>
